#!/bin/bash

git pull origin master

#rm -f src/main/resources/application.properties
#cp ./application.properties src/main/resources/

mvn clean package -Dmaven.test.skip=true -Preal

TAR=target
DIR=/fafa/app/bawangcan
JARFILE=bawangcan.jar
echo "关闭应用...."
#ps -ef | grep $JARFILE | grep -v grep | awk '{print $2}' | xargs kill -9
ps -fe |grep $JARFILE |awk 'NR==1{print $2}'| xargs kill -9

echo "备份应用文件...."

if [ ! -d $DIR/backup ];then
   mkdir -p $DIR/backup
fi

cd $DIR

mv $JARFILE backup/$JARFILE$DATE

echo "拷贝应用文件...."
mv -f /fafa/xm/bawangcan/target/$JARFILE  .

echo "启用应用...."
nohup java -jar $JARFILE  >./bawangcan.log 2>&1 &

if [ $? = 0 ];then
        sleep 15
        tail -n 50 ./bawangcan.log
fi

echo "删除过期备份...."
cd backup/
ls -lt|awk 'NR>5{print $NF}'|xargs rm -rf

echo "启动成功OK"
